//
//  ProfitViewController.m
//  beautyLamp
//
//  Created by Tam Kwok To Michael on 2017/9/21.
//  Copyright © 2017年 Tam Kwok To Michael. All rights reserved.
//

#import "ProfitViewController.h"
#import "BLHeader.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "ProfitRecordViewController.h"
#import "ClockProfitViewDesViewController.h"
#import "ApplyDrawViewController.h"
#import "ProfitNet.h"
#import <MBProgressHUD.h>

@interface ProfitViewController ()

@property (weak, nonatomic) IBOutlet UIButton *myProfitLabel;
@property (weak, nonatomic) IBOutlet UIButton *clockProfitLabel;
@property (weak, nonatomic) IBOutlet UIButton *drawProfitLabel;

@property (nonatomic, strong) NSString *freeMoney;
@property (nonatomic, strong) NSString *clockMoney;
@property (nonatomic, strong) NSString *drawMoney;

@end

@implementation ProfitViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
   
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self getProfit];
}

- (void)getProfit {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    [ProfitNet getMyProfit:^(id result, NSError *error) {
        _freeMoney = [result objectForKey:@"freeMoney"];
        _clockMoney = [result objectForKey:@"surplus"];
        _drawMoney = [result objectForKey:@"userEarnings"];
        [self.myProfitLabel setTitle:[NSString stringWithFormat:@"我的总收益：￥%.3f",[_drawMoney floatValue]] forState:UIControlStateNormal];
        [self.clockProfitLabel setTitle:[NSString stringWithFormat:@"剩余收益：￥%.3f",[_clockMoney floatValue]] forState:UIControlStateNormal];
        [self.drawProfitLabel setTitle:[NSString stringWithFormat:@"可提现：￥%.2f",[_freeMoney floatValue]] forState:UIControlStateNormal];
        [hud hideAnimated:YES];
    }];
    
    NSString *class = [[NSUserDefaults standardUserDefaults] objectForKey:USERCLASS];
//    if ([class integerValue] == 2) {
//        [self.clockProfitLabel setHidden:YES];
//        [self.lineView setHidden:YES];
//    }
}


- (void)setupUI {
    self.title = @"收益";
    self.edgesForExtendedLayout = UIRectEdgeNone;
}

#pragma mark 收益记录
- (IBAction)myProfit:(id)sender {
    ProfitRecordViewController *vc = [[ProfitRecordViewController alloc] init];
    vc.vcTitle = @"收益记录";
    vc.leftTitle = [NSString stringWithFormat:@"总收益：￥%@", _freeMoney];
    vc.rightTitle = [NSString stringWithFormat:@"剩余收益：￥%@",_clockMoney];
    vc.isMiun = NO;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 锁定
- (IBAction)clockProfit:(id)sender {
    ClockProfitViewDesViewController *controller = [[ClockProfitViewDesViewController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
}

#pragma mark 提现记录
- (IBAction)withDrawRecord:(id)sender {
    ProfitRecordViewController *vc = [[ProfitRecordViewController alloc] init];
    vc.vcTitle = @"提现记录";
    vc.leftTitle = @"总提现：￥";
    vc.rightTitle = [NSString stringWithFormat:@"可提现：￥%@",_drawMoney];
    vc.isMiun = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 申请提现
- (IBAction)withDrawProfit:(id)sender {
    ApplyDrawViewController *controller = [[ApplyDrawViewController alloc] init];
    controller.totalProfit = [self.clockMoney floatValue];
    controller.drawProfit = [self.freeMoney floatValue];
    [self.navigationController pushViewController:controller animated:YES];
}
@end
